//
//  JHSSetAndHelpViewController.m
//  JHSSweep
//
//  Created by 卢春晖 on 2017/3/23.
//  Copyright © 2017年 JHDS. All rights reserved.
//

#import "JHSSetAndHelpViewController.h"
#import "JHSSetOrHelpCell.h"
#import "JHSticklingController.h"
#import "JHSAlterCodeViewController.h"
#import "JHSLogInDetailController.h"
#import "JHSHomeViewController.h"

static NSString *helpID = @"helpID";
@interface JHSSetAndHelpViewController (){
    NSDictionary *_dic;
}

@end

@implementation JHSSetAndHelpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   [self setupUI];
    
}
-(void)setupUI{
    //表尾 小技巧：给表尾添加一个空的UIView就可以删除其他行
    self.tableView.tableFooterView = [[UIView alloc]init];
    //推到详细页之后,隐藏底部的tabbar
    self.hidesBottomBarWhenPushed = YES;

  
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:helpID];
    
    self.tableView.rowHeight = 50;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   // JHSSetOrHelpCell *cell = [tableView dequeueReusableCellWithIdentifier:helpID forIndexPath:indexPath];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:helpID forIndexPath:indexPath];
    switch (indexPath.row) {
        case 0:
        {
            
            _dic =@{@"name":@"意见反馈",@"icon":@"意见反馈"};
            break;}
        case 1:
        {
            _dic =@{@"name":@"加符号说明",@"icon":@"说明"};
            break;}
        case 2:
        {
            _dic =@{@"name":@"修改密码",@"icon":@"修改密码"};
            break;
        }
        case 3:
        {
            _dic =@{@"name":@"清除缓存",@"icon":@"清除缓存"};
            break;
        }
        case 4:
        {
            _dic =@{@"name":@"注销",@"icon":@"注销set"};
            break;
        }
        default:
            break;
    }
    
    UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:_dic[@"icon"]]];
    [cell.imageView sizeToFit];
    [cell.contentView addSubview:imgV];
    
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cell.contentView.mas_left).offset(10);
        make.centerY.equalTo(cell.contentView.mas_centerY);
        make.size.mas_offset(CGSizeMake(30, 30));
    }];
    
    

    UILabel *textLabel = [[UILabel alloc]init];
    textLabel.text = _dic[@"name"];
    [cell.contentView addSubview:textLabel];
    [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgV.mas_right).offset(10);
        make.centerY.equalTo(cell.contentView.mas_centerY);
    }];
    
    UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"position-right"]];
   [cell.contentView addSubview:img];
    [img sizeToFit];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(cell.contentView.mas_right).offset(-10);
       make.centerY.equalTo(cell.mas_centerY);
    }];
    
    return cell;
}


//MARK:选中某一行执行
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        NSLog(@"意见反馈");
        //设置与帮助
        JHSticklingController *detail = [JHSticklingController new];
        //推到详细页之后,隐藏底部的tabbar
       detail.hidesBottomBarWhenPushed = YES;
        
       [self.navigationController pushViewController:detail animated:YES];
    }else if (indexPath.row == 1) {
        
        //
        NSLog(@"加符号说明");
    }
    else if (indexPath.row == 2) {
        NSLog(@"修改密码");
        JHSAlterCodeViewController *alterCode = [[JHSAlterCodeViewController alloc]init];
        alterCode.hidesBottomBarWhenPushed = YES;
        //self.navigationController.navigationBarHidden = YES;
        //self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
        [self.navigationController pushViewController:alterCode animated:YES];
    }
    else if (indexPath.row == 3) {
        
        [JHSSetAndHelpViewController jhsShowSVSuccessTitle:@"清除67.3M垃圾" andTime:1];
        
        
    }else{
        NSLog(@"注销");
        
        [JHSSetAndHelpViewController jhsShowSVSuccessTitle:@"注销成功" andTime:1];
        JHSLogInDetailController *vc = [[JHSLogInDetailController alloc]init];
        
//        JHSHomeViewController *vcHome=[JHSHomeViewController new];
//        self.navigationController.navigationItem.backBarButtonItem=nil;
        [vc.navigationItem setHidesBackButton:YES];
        
        [self.navigationController  pushViewController:vc animated:YES];
        
        
    }
}


+ (void)jhsShowSVSuccessTitle:(NSString *)content andTime:(float)delay{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setBackgroundColor:JHSMainColor];
    [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"%@",content]];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}

@end
